package cn.wizzer.app.sys.modules.services.impl;

import cn.wizzer.app.sys.modules.models.SysIPTables;
import cn.wizzer.app.sys.modules.services.SysIPTablesService;
import cn.wizzer.framework.base.service.BaseServiceImpl;
import com.alibaba.dubbo.config.annotation.Service;
import org.nutz.dao.Cnd;
import org.nutz.dao.Dao;
import org.nutz.ioc.loader.annotation.IocBean;
import org.nutz.plugins.wkcache.annotation.CacheDefaults;
import org.nutz.plugins.wkcache.annotation.CacheRemoveAll;
import org.nutz.plugins.wkcache.annotation.CacheResult;

import java.util.List;
import java.util.stream.Collectors;


@IocBean(args = {"refer:dao"})
@Service(interfaceClass = SysIPTablesService.class)
@CacheDefaults(cacheName = "sys_ip_tables")
public class SysIPTablesServiceImpl extends BaseServiceImpl<SysIPTables> implements SysIPTablesService {
    public SysIPTablesServiceImpl(Dao dao) {
        super(dao);
    }

    @Override
    @CacheResult
    public List<String> queryAll() {
        return this.query(Cnd.where("disabled","=",false))
                .stream()
                .map(SysIPTables::getIp)
                .collect(Collectors.toList());
    }

    @Override
    public void add(SysIPTables ip) {
        this.insert(ip);
        this.clearCache();
    }

    @Override
    public void del(String id) {
        this.delete(id);
        this.clearCache();
    }

    @Override
    public void update(SysIPTables ip) {
        this.updateIgnoreNull(ip);
        this.clearCache();
    }


    @Override
    @CacheRemoveAll
    public void clearCache() {
    }

}
